<?php

namespace app\repository;

use app\common\OpenInfoBean;
use app\models\OpenInfo;

class OpenInfoRepository extends BaseRepository
{
    /**
     * @param string $appid
     * @param string $openid
     * @param int $thirdType
     * @param array $fields
     * @return array|null|OpenInfo
     */
    public function getOpenInfoByOpenid(string $appid, string $openid, int $thirdType, array $fields = ['*']): array
    {
        return OpenInfo::find()->select($fields)->where(['app_id' => $appid, 'third_type' => $thirdType, 'openid' => $openid])->one();
    }

    /**
     * @param string $appid
     * @param string $openid
     * @param array $fields
     * @return array|null|OpenInfo
     */
    public function getOfficialAccountOne(string $appid, string $openid, array $fields = ['*']): array
    {
        return OpenInfo::find()->select($fields)->where(['app_id' => $appid, 'third_type' => OpenInfoBean::THIRD_TYPE_OFFICIAL, 'openid' => $openid])->one();
    }

}